package com.ccp.dev.qbdms.controller;

import static com.ccp.dev.extend.service.ExtendSysFileService.compress;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ccp.dev.core.basic.annotion.Action;
import com.ccp.dev.core.basic.consts.UrlConstants;
import com.ccp.dev.core.basic.internationalization.SysBaseController;
import com.ccp.dev.core.basic.util.ContextUtil;
import com.ccp.dev.core.basic.util.PropertyUtil;
import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.core.poi.excel.reader.TableEntity;
import com.ccp.dev.core.util.AppUtil;
import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.core.util.DateFormatUtil;
import com.ccp.dev.core.util.FileUtil;
import com.ccp.dev.core.util.RequestUtil;
import com.ccp.dev.core.util.StringUtil;
import com.ccp.dev.core.util.TimeUtil;
import com.ccp.dev.core.util.log.SysAuditThreadLocalHolder;
import com.ccp.dev.extend.service.ExtendSysFileService;
import com.ccp.dev.extend.service.ExtendSysOrgService;
import com.ccp.dev.extend.util.ServiceUtil;
import com.ccp.dev.form.service.impl.ScriptImpl;
import com.ccp.dev.qbdms.consts.ZhiLiangConst;
import com.ccp.dev.qbdms.enums.FlowStatusEnum;
import com.ccp.dev.qbdms.expimp.CustomExcelReader;
import com.ccp.dev.qbdms.expimp.util.AbstractExpUtil;
import com.ccp.dev.qbdms.expimp.util.AbstractImpUtil;
import com.ccp.dev.qbdms.expimp.util.AuxiliaryUtil;
import com.ccp.dev.qbdms.model.WQbdCalRewandpuns;
import com.ccp.dev.qbdms.model.WQbdFalProblemPlan;
import com.ccp.dev.qbdms.model.WQbdFalProblemreset;
import com.ccp.dev.qbdms.model.WQbdFalProblemvso;
import com.ccp.dev.qbdms.model.WQbdFalSupervise;
import com.ccp.dev.qbdms.model.WQbdProblemProgress;
import com.ccp.dev.qbdms.model.WQbdXhdh;
import com.ccp.dev.qbdms.service.WCustomColumnsService;
import com.ccp.dev.qbdms.service.WQbdCalRewandpunsService;
import com.ccp.dev.qbdms.service.WQbdFalProblemPlanService;
import com.ccp.dev.qbdms.service.WQbdFalProblemresetService;
import com.ccp.dev.qbdms.service.WQbdFalProblemvsoService;
import com.ccp.dev.qbdms.service.WQbdFalSuperviseService;
import com.ccp.dev.qbdms.service.WQbdReportTemplateService;
import com.ccp.dev.qbdms.service.WQbdXhdhService;
import com.ccp.dev.qbdms.util.Base64Util;
import com.ccp.dev.qbdms.util.BaseUtil;
import com.ccp.dev.qbdms.util.PdfUtils;
import com.ccp.dev.qbdms.util.ProcessingTimeUtil;
import com.ccp.dev.qbdms.util.ProjectUUIDUtils;
import com.ccp.dev.system.model.Dictionary;
import com.ccp.dev.system.model.GlobalType;
import com.ccp.dev.system.model.SysOrg;
import com.ccp.dev.system.model.SysRole;
import com.ccp.dev.system.model.SysUser;
import com.ccp.dev.system.service.DictionaryService;
import com.ccp.dev.system.service.GlobalTypeService;
import com.ccp.dev.system.service.SysFileService;
import com.ccp.dev.system.service.SysOrgService;
import com.ccp.dev.system.service.SysUserService;
import com.ccp.dev.workflow.model.ProcessRun;
import com.ccp.dev.workflow.model.TaskOpinion;
import com.ccp.dev.workflow.model.bpm.ProcessCmd;
import com.ccp.dev.workflow.service.ProcessRunService;
import com.ccp.dev.workflow.service.TaskOpinionService;
import com.google.common.collect.Maps;
import java.io.File;
import java.nio.file.Files;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

/**
 * 质量问题管理 信息操作处理控制器
 *
 * @author sun
 * @date 2020-05-06 15:57:36
 */
@Controller
/**
 * 请将此名称添加到日志开关
 */
@Action(customModel = "质量问题管理")
@RequestMapping("/qbdms/wQbdFalProblemreset")
public class WQbdFalProblemresetController extends SysBaseController {

	@Resource
	private WQbdFalProblemresetService wQbdFalProblemresetService;
	@Resource
	private DictionaryService dictionaryService;
	@Resource
	private WCustomColumnsService wCustomColumnsService;
	@Resource
	private WQbdXhdhService wQbdXhdhService;
	@Resource
	private GlobalTypeService globalTypeService;
	@Resource
	private WQbdCalRewandpunsService wQbdCalRewandpunsService;
	@Resource
	private ScriptImpl scriptImpl;
	@Resource
	private WQbdFalProblemvsoService wQbdFalProblemvsoService;
	@Resource
	private WQbdFalSuperviseService wQbdFalSuperviseService;
	@Resource
	private WQbdReportTemplateService wQbdReportTemplateService;
	@Resource
	private SysOrgService sysOrgService;
	@Resource
	private WQbdFalProblemPlanService wQbdFalProblemPlanService;
	@Resource
	private ExtendSysOrgService extendSysOrgService;
	@Resource
	private SysUserService sysUserService;
	@Resource
	private ProcessRunService processRunService;
	@Resource
	private TaskOpinionService taskOpinionService;
	// 跟踪参数
	public static final String GZ = "track";
	// 与从督办传过来的参数做比较
	public static final String DB = "db";


	/**
	 * 功能描述: 跳转到首页
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_LIST)
	@Action(description = "跳转到质量问题管理首页", exectype = "页面跳转日志")
	public String viewList(HttpServletRequest request, ModelMap modelMap) {
		wCustomColumnsService.addCustomCols(request);
		this.viewAdd(request, modelMap);
		try {
			modelMap.put("flowStatusList", JSON.toJSONString(FlowStatusEnum.getFlowStatusList()));
			modelMap.put("originOrgList",
					JSON.toJSONString(wQbdFalProblemresetService.getOriginOrgToDicList()));
			modelMap.put("currentUserId", scriptImpl.getCurrentUserId());
			modelMap.put("currentSystemLevel", BaseUtil.getCurrentSystemLevel());
			SysRole sysRole = (SysRole) request.getSession().getAttribute(SysRole.CURRENT_SYSROLE);
			modelMap.put("roleAlias", sysRole.getAlias());
			modelMap.put("researchRoomList", JSON.toJSONString(sysOrgService
					.querySubSysOrgBySupOrgIdNoChild(sysOrgService.getSysOrgByOrgCode("wrj").getOrgId())));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return "wQbdFalProblemreset/list";
	}


	@Resource
	private RestHighLevelClient restHighLevelClient;
	@Resource
	private ScriptImpl script;


	/**
	 * 功能描述: 附带检索条件的分页查询
	 *
	 * @param: [request] http请求
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.MODULE_FUNCTION_LIST)
	@ResponseBody
	@Action(description = "附带检索条件的分页查询质量问题管理", detail = "查询数据信息<#if success>成功<#else></#if>")
	public Object list(HttpServletRequest request, ModelMap modelMap) throws IllegalAccessException {
		String path = BaseUtil.getCurrentTenOrgCodePath();
		QueryFilter queryFilter = new QueryFilter(request, true);
		// 处理状态搜索
		if (queryFilter.containsKey("reportStatusOne")) {
			String status = String.valueOf(queryFilter.get("reportStatusOne"));
			queryFilter.put("reportStatusOne", ZhiLiangConst.wrapStatusCode(status));
		}

		//  zhl ------------------------------------------------------------------
		List<Dictionary> dicList = dictionaryService.getDicByNodeKey("mj", false);

		ZhiLiangConst.addQueryFilter(queryFilter);
		if (null != queryFilter.get("workPhaseType")
				&& Integer.parseInt(String.valueOf(queryFilter.get("workPhaseType")))
				== wQbdReportTemplateService.DEVELOPMENT) {
			//指定型号研制阶段
			queryFilter.addFilter("modeldev", "'模样', '初样', '试样', '定型'");
		}
		if (null != queryFilter.get("workPhaseType")
				&& Integer.parseInt(String.valueOf(queryFilter.get("workPhaseType")))
				== wQbdReportTemplateService.MASS_PRODUCTION) {
			//指定型号批产阶段
			queryFilter.addFilter("modeldev", "'批产'");
		}
		if (StringUtils.isNotBlank(RequestUtil.getString(request, "tjgz"))) {
			if ("aydtj".equals(RequestUtil.getString(request, "tjgz"))) {
				try {
					List<Map<String, Object>> mapList = ProcessingTimeUtil
							.packagingTime("aydtj", DateUtils
											.parseDate(RequestUtil.getString(request, "beginTime"), "yyyy-MM"),
									DateUtils.parseDate(RequestUtil.getString(request, "endTime"),
											"yyyy-MM"));
					queryFilter.addFilter("beginTime", mapList.get(0).get("startTime"));
					queryFilter
							.addFilter("endTime", mapList.get(mapList.size() - 1).get("endTime"));
				} catch (ParseException e) {
					e.printStackTrace();
				}
			} else {
				try {
					List<Map<String, Object>> mapList = ProcessingTimeUtil
							.packagingTime("andtj", DateUtils
											.parseDate(RequestUtil.getString(request, "beginTime"), "yyyy"),
									DateUtils.parseDate(RequestUtil.getString(request, "endTime"),
											"yyyy"));
					queryFilter.addFilter("beginTime", mapList.get(0).get("startTime"));
					queryFilter
							.addFilter("endTime", mapList.get(mapList.size() - 1).get("endTime"));
				} catch (ParseException e) {
					e.printStackTrace();
				}
			}
		}
		if (null != queryFilter.get("isOther")) {
			if ("0".equals(queryFilter.get("isOther"))) {
				queryFilter.addFilter("isJunMao", "1");
				queryFilter.addFilter("isOther", "");
			}
		}
		List<WQbdFalProblemreset> pageDatas = wQbdFalProblemresetService.queryList(queryFilter);
		ZhiLiangConst.showName(pageDatas);
		//没有上报可以忽略这个
		ZhiLiangConst.isDataAllowEdit(pageDatas, true);
		//判断流程状态
		ZhiLiangConst.isDataAllowEditByFlowStatus(pageDatas);

		SysAuditThreadLocalHolder.putParamerter("success", true);
		return success(pageDatas, queryFilter.getPageBean().getTotalCount());

	}

	/**
	 * 查询上报的信息
	 */
	@RequestMapping("/reportList")
	@ResponseBody
	public Object reportList(HttpServletRequest request, @RequestParam("id") String id,
			@RequestParam("tableName") String tableName) {
		//业务数据
		List<WQbdFalProblemreset> reportList = wQbdFalProblemresetService.reportList(id, tableName);
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return getResultDataSuccess("options.success", reportList);
	}


	private void setDicToModelMap(String key, ModelMap modelMap) {
		List<Dictionary> dicList = dictionaryService.getDicByNodeKey(key, false);
		modelMap.put(key + "List", JSON.toJSONString(dicList));
	}

	/**
	 * 功能描述: 跳转到新增页面
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_ADD_UPDATE)
	@Action(description = "跳转到质量问题管理新增页面", exectype = "页面跳转日志")
	public String viewAdd(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");
		modelMap.put("id", id);
		SysRole sysRole = (SysRole) request.getSession().getAttribute(SysRole.CURRENT_SYSROLE);
		if (sysRole.getAlias().equals("bpm_dwxhzly")) {
			modelMap.put("isInclude", "true");
		}
		if (StringUtils.isNotBlank(id)) {
			WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(id);
			modelMap.put("flowStatus", wQbdFalProblemreset.getFlowStatus());
			if (null != wQbdFalProblemreset.getfCausationclass1()) {
				modelMap.put("isInclude", "true");
			}
		}
		String runId = "";
		List<TaskOpinion> taskOpinionNewList = new ArrayList<TaskOpinion>();
		ProcessRun processRun = processRunService.getByBusinessKey(id);
		if (BeanUtils.isNotEmpty(processRun)) {
			runId = processRun.getRunId();
			List<TaskOpinion> taskOpinionList = taskOpinionService.getByRunId(runId);
			for (TaskOpinion taskOpinion : taskOpinionList) {
				if (taskOpinion.getEndTime() != null) {
					taskOpinionNewList.add(taskOpinion);
				}
			}
		}
		modelMap.put("taskOpinionNewList", taskOpinionNewList);

//        密级
		setDicToModelMap("mj", modelMap);
//        是否
		setDicToModelMap("sf", modelMap);
//        型号研制阶段
		setDicToModelMap("xhyzjd", modelMap);
//        型号类别
		setDicToModelMap("xhlx", modelMap);
//        工作阶段
		setDicToModelMap("gzjd", modelMap);
//        生产分类
		setDicToModelMap("scfl", modelMap);
//        故障件阶段
		setDicToModelMap("gzjjd", modelMap);
//        产品级别
		setDicToModelMap("cpjb", modelMap);
//        是否三类问题
		setDicToModelMap("spslwt", modelMap);
//        问题等级
		setDicToModelMap("wtdj", modelMap);
//        硬件/软件
		setDicToModelMap("yjrj", modelMap);
//        问题级别
		setDicToModelMap("wtjb", modelMap);
//        问题处理方式
		setDicToModelMap("wtclfs", modelMap);
//        责任单位性质
		setDicToModelMap("zrswxz", modelMap);
//        归零方式
		setDicToModelMap("glfs", modelMap);
//        解决情况
		setDicToModelMap("jjqk", modelMap);
//        行业
		setDicToModelMap("xy", modelMap);
//        外协性质
		setDicToModelMap("wxxz", modelMap);
//        软件等级
		setDicToModelMap("rjdj", modelMap);
//        责任追究类别
		setDicToModelMap("zrzjlb", modelMap);
//        原因分类
		setDicToModelMap("yyfls", modelMap);
		// 型号代号
		List<WQbdXhdh> wQbdXhdhs = wQbdXhdhService.getAll();
		modelMap.put("wQbdXhdhs", JSON.toJSONString(wQbdXhdhs));

		//原因分类树的globalType，为了获取到原因分类根节点的id，作为前端初始化id，
//         不应该直接写死在前端，所以从后端传过去
		GlobalType yyfls = globalTypeService.getByDictNodeKey("yyfls");
		modelMap.put("typeId", yyfls.getTypeId());
		modelMap.put("researchRoomList", JSON.toJSONString(sysOrgService
				.querySubSysOrgBySupOrgIdNoChild(sysOrgService.getSysOrgByOrgCode("wrj").getOrgId())));

		if (StringUtil.isEmpty(id)) {
			SysUser sysUser = (SysUser) ContextUtil.getCurrentUser();
			SysOrg sysOrg = (SysOrg) ContextUtil.getCurrentOrg();
			modelMap.put("filldept", sysOrg.getOrgName());
			modelMap.put("fillman", sysUser.getFullName());
			modelMap.put("filldate", TimeUtil.getCurrentDate());
			modelMap.put("fillmanaccount", sysUser.getAccount());
			modelMap.put("filldeptid", sysOrg.getCode());
		}
		String fileManagementUploadType = PropertyUtil.getByAlias("fileManagementUploadType", "");
		modelMap.put("fileManagementUploadType", fileManagementUploadType);
		String wjszsdsxlx = PropertyUtil.getByAlias("wjszsdsxlx", "");
		modelMap.put("wjszsdsxlx", wjszsdsxlx);
		return "wQbdFalProblemreset/add";
	}

	/**
	 * 功能描述: 跳转到新增页面
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/addSanYuan")
	@Action(description = "跳转到质量问题管理新增页面（三院）", exectype = "页面跳转日志")
	public String viewAddSanYuan(HttpServletRequest request, ModelMap modelMap) {
		this.viewAdd(request, modelMap);

		String did = RequestUtil.getString(request, "did");
		if (StringUtil.isNotEmpty(did)) {
			modelMap.put("did", did);
			modelMap.put("db", "db");
			// 根据督办id 去查询督办的内容 用来回填质量问题信息
			// 督办的数据回填
			WQbdFalSupervise wQbdFalSupervise = wQbdFalSuperviseService.getOneById(did);
			// 型号代号
			modelMap.put("dbdh", wQbdFalSupervise.getfModelsymbol());
			// 型号名称
			modelMap.put("dbmc", wQbdFalSupervise.getfModelname());
			// 问题责任单位
			modelMap.put("dbzrdw", wQbdFalSupervise.getfDutydept());
//            wQbdFalSupervise.getfDutydeptId();
			// 问题现象
			modelMap.put("dbwtxx", wQbdFalSupervise.getfFailuredescription());
		}

		return "wQbdFalProblemreset/addSanYuan";
	}

	/**
	 * 功能描述:  数据保存通用方法
	 *
	 * @param: wQbdFalProblemreset 保存的对象
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.MODULE_FUNCTION_SAVE)
	@ResponseBody
	@Action(description = "保存质量问题管理数据", detail = "<#if isAdd>新增<#else>编辑</#if>质量问题管理数据<#if success>成功<#else>失败</#if>")
	public Object save(@RequestBody WQbdFalProblemreset wQbdFalProblemreset) {
		String id = wQbdFalProblemreset.getId();
		int result;
		wQbdFalProblemreset.setfUpdateby(scriptImpl.getCurrentUserId());
		wQbdFalProblemreset.setfUpdatetime(new Date());
		if (StringUtils.isBlank(wQbdFalProblemreset.getfDutydept())) {
			wQbdFalProblemreset.setfDutydept("302所");
		}
		if (StringUtil.isEmpty(id)) {
			SysAuditThreadLocalHolder.putParamerter("isAdd", true);
			//新增操作
			//新增数据前生成随机Id
			wQbdFalProblemreset.setId(ProjectUUIDUtils.getUUIDFor32());
			ZhiLiangConst.addCommonFields(wQbdFalProblemreset);
			wQbdFalProblemreset.setFlowStatus(FlowStatusEnum.NOT_SUBMIT.getValue());
			wQbdFalProblemreset.setTenantId(ContextUtil.getCurrentUserTenantId());
			wQbdFalProblemreset.setReportStatus(ZhiLiangConst.getDataInitStatusToHospital());
			wQbdFalProblemreset.setfCreateby(scriptImpl.getCurrentUserId());
			wQbdFalProblemreset.setfCreatetime(new Date());
			result = wQbdFalProblemresetService.add(wQbdFalProblemreset);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			//修改操作
			wQbdFalProblemreset.setfUpdatetime(new Date());
			wQbdFalProblemreset.setfUpdateby(scriptImpl.getCurrentUserId());
			ZhiLiangConst.updateCommonFields(wQbdFalProblemreset);
			result = wQbdFalProblemresetService.update(wQbdFalProblemreset);
		}
		if (result > 0) {
			SysAuditThreadLocalHolder.putParamerter("success", true);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
		}
		Map<String, Object> idMap = Maps.newHashMap();
		idMap.put("id", wQbdFalProblemreset.getId());
		return result > 0 ? getResultDataSuccess("save.success", idMap)
				: getResultDataError("save.failure");
	}

	/**
	 * 功能描述:  数据保存归零处理
	 *
	 * @param: wQbdFalProblemreset 保存的对象
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping("/savegl")
	@ResponseBody
	@Action(description = "数据保存归零处理", detail = "<#if isAdd>新增<#else>编辑</#if>质量问题管理数据<#if success>成功<#else>失败</#if>")
	public Object savegl(@RequestBody WQbdFalProblemreset wQbdFalProblemreset) {
		int result;
		SysAuditThreadLocalHolder.putParamerter("success", false);
		//修改操作
		wQbdFalProblemreset.setfUpdatetime(new Date());
		wQbdFalProblemreset.setfUpdateby(scriptImpl.getCurrentUserId());
		result = wQbdFalProblemresetService.updategl(wQbdFalProblemreset);

		if (result > 0) {
			SysAuditThreadLocalHolder.putParamerter("success", true);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
		}
		return result > 0 ? getResultDataSuccess("save.success") : getResultDataError("save.failure");
	}

	/**
	 * 功能描述: 跳转到详情页面
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/particulars")
	@Action(description = "跳转到质量问题管理详情页面", exectype = "页面跳转日志")
	public String viewParticulars(HttpServletRequest request, ModelMap modelMap) {
		String flag = RequestUtil.getString(request, "flag");
		modelMap.put("flag", flag);
		String id = RequestUtil.getString(request, "id");
		String mark = RequestUtil.getString(request, "mark");
		String isClose = RequestUtil.getString(request, "isClose");
		String isShow = RequestUtil.getString(request, "isShow");
		modelMap.put("id", id);
		modelMap.put("systemLevel", BaseUtil.getCurrentSystemLevel());
		modelMap.put("isClose", isClose);
		modelMap.put("isShow", isShow);
		modelMap.put("backUrl", RequestUtil.getString(request, "backUrl"));
		if (StringUtil.isNotEmpty(mark) && DB.equals(mark)) {
			modelMap.put("mark", mark);
		}
		//获取当前节点信息
		WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(id);
		modelMap.put("flowStatus", wQbdFalProblemreset.getFlowStatus());
		//获取意见框信息
		String runId = "";
		List<TaskOpinion> taskOpinionNewList = new ArrayList<TaskOpinion>();
		ProcessRun processRun = processRunService.getByBusinessKey(id);
		if (BeanUtils.isNotEmpty(processRun)) {
			runId = processRun.getRunId();
			List<TaskOpinion> taskOpinionList = taskOpinionService.getByRunId(runId);
			for (TaskOpinion taskOpinion : taskOpinionList) {
				if (taskOpinion.getEndTime() != null) {
					taskOpinionNewList.add(taskOpinion);
				}
			}
			modelMap.put("runId", runId);
			modelMap.put("processRun", processRun);
		}
		modelMap.put("taskOpinionNewList", taskOpinionNewList);

		this.viewAdd(request, modelMap);
		return "wQbdFalProblemreset/particulars";
	}

	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/progress")
	@Action(description = "跳转到反馈周进展", exectype = "页面跳转日志")
	public String viewProgress(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");
		String isClose = RequestUtil.getString(request, "isClose");
		modelMap.put("id", id);
		modelMap.put("isClose", isClose);
		this.viewAdd(request, modelMap);
		return "wQbdFalProblemreset/progress";
	}

	@RequestMapping("/getAllProgress")
	@ResponseBody
	@Action(description = "获取所有周进展", exectype = "页面跳转日志")
	public Object getAllProgress(String id) {
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return JSON.toJSONStringWithDateFormat(
				getResultDataSuccess("get.success", wQbdFalProblemresetService.getAllProgress(id)),
				"yyyy-MM-dd");
	}

	@RequestMapping("/saveProgress")
	@ResponseBody
	@Action(description = "保存周进展", exectype = "页面跳转日志")
	public Object getAllProgress(WQbdProblemProgress wQbdProblemProgress) {
		wQbdProblemProgress.setCreateTime(new Date());
		wQbdProblemProgress.setId(ProjectUUIDUtils.getUUIDFor32());
		int result = wQbdFalProblemresetService.saveProgress(wQbdProblemProgress);
		if (result > 0) {
			SysAuditThreadLocalHolder.putParamerter("success", true);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
		}
		return result > 0 ? getResultDataSuccess("save.success")
				: getResultDataError("save.failure");
	}

	/**
	 * 功能描述: 跳转到详情页面
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/particularsSanYuan")
	@Action(description = "跳转到质量问题管理详情页面（三院）", exectype = "页面跳转日志")
	public String particularsSanYuan(HttpServletRequest request, ModelMap modelMap) {
		viewParticulars(request, modelMap);
		return "wQbdFalProblemreset/particularsSanYuan";
	}


	@RequestMapping("/confirmZero")
	@ResponseBody
	@Action(description = "确认归零", detail = "根据主键id查询质量问题管理的数据<#if success>成功<#else>失败</#if>")
	public Object confirmZero(@RequestParam("idArrStr") String idArrStr) {
		try {
			String[] idArr = idArrStr.split(",");
			wQbdFalProblemresetService.confirmZero(idArr);
		} catch (Exception e) {
			e.printStackTrace();
			SysAuditThreadLocalHolder.putParamerter("success", false);
			//return getResultDataError("bad.item.operate");
			return fail("归零失败!");
		}
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return getResultDataSuccess("operation.success");
	}

	/**
	 * 查看历史版本
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/histories")
	@Action(description = "跳转到质量问题历史版本页面", exectype = "页面跳转日志")
	public String viewHistorys(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");

		modelMap.put("id", id);
		return "wQbdFalProblemreset/histories";
	}

	/**
	 * 查看历史版本
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/historiesSanYuan")
	@Action(description = "跳转到质量问题历史版本页面（三院）", exectype = "页面跳转日志")
	public String historiesSanYuan(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");

		modelMap.put("id", id);
		return "wQbdFalProblemreset/historiesSanYuan";
	}


	@RequestMapping("/getHistories")
	@ResponseBody
	@Action(description = "根据主键id查询历史数据", detail = "根据主键id查询质量问题管理的数据<#if success>成功<#else>失败</#if>")
	public Object getHistories(@RequestParam("id") String id) {
		WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(id);
		wQbdFalProblemreset.setTitle("最近一次修改");
		if (null == wQbdFalProblemreset) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return getResultDataError("get.failure");
		}
		ArrayList<Object> resultList = new ArrayList<>();
		resultList.add(wQbdFalProblemreset);

		List<WQbdFalProblemvso> allVersionList = wQbdFalProblemvsoService.getAllById(id);
		List<WQbdFalProblemvso> historiesList = new ArrayList<>();
		List<String> titleList = new ArrayList<>();
		int i = 0;
		//默认展示3条以内的历史数据，所以当i<3时，将数据放入展示的List中
		for (WQbdFalProblemvso wQbdFalProblemvso : allVersionList) {
			Date fVersiondate = wQbdFalProblemvso.getfVersiondate();
			if (fVersiondate == null) {
				continue;
			}
			if (i < 3) {
				historiesList.add(wQbdFalProblemvso);
			}
			titleList.add(DateFormatUtil.format(fVersiondate, "yyyy-MM-dd HH:mm:ss"));
			i++;
		}
		for (WQbdFalProblemvso wQbdFalProblemvso : historiesList) {
			wQbdFalProblemvso.setTitle(titleList);
		}

		resultList.addAll(historiesList);
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return getResultDataSuccess("get.success", resultList);
	}

	/**
	 * 归零确认单
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/zero")
	@Action(description = "跳转到归零确认单页面", exectype = "页面跳转日志")
	public String viewZero(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");
		String pdf = request.getParameter("pdf");
		modelMap.put("pdf", pdf);
		modelMap.put("id", id);
		this.viewAdd(request, modelMap);
		this.get(id, modelMap);
		return "wQbdFalProblemreset/zero";
	}

	/**
	 * 归零确认单
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/zeroSanYuan")
	@Action(description = "跳转到归零确认单页面（三院）", exectype = "页面跳转日志")
	public String viewZeroSanYuan(HttpServletRequest request, ModelMap modelMap) {
		String id = RequestUtil.getString(request, "id");
		String pdf = request.getParameter("pdf");
		modelMap.put("pdf", pdf);
		modelMap.put("id", id);
		this.viewAdd(request, modelMap);
		this.get(id, modelMap);
		return "wQbdFalProblemreset/zeroSanYuan";
	}

	@RequestMapping("/getHistoryByTime")
	@ResponseBody
	@Action(description = "根据主键id和版本时间查询质量问题管理的一条数据", detail = "根据主键id查询质量问题管理的数据<#if success>成功<#else>失败</#if>")
	public Object getHistoryByTime(@RequestParam("fVersiondate") String fVersiondate,
			@RequestParam("id") String id) {
		WQbdFalProblemvso wQbdFalProblemvso = wQbdFalProblemvsoService
				.getOneByIdAndVersionTime(id, fVersiondate);
		if (null == wQbdFalProblemvso) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return getResultDataError("get.failure");
		}
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return getResultDataSuccess("get.success", wQbdFalProblemvso);
	}

	/**
	 * 功能描述: 根据主键id获取一条数据的通用查询方法
	 *
	 * @param: id 参数对象必须是"id"
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.MODULE_FUNCTION_GET)
	@ResponseBody
	@Action(description = "根据主键id查询质量问题管理的一条数据", detail = "根据主键id查询质量问题管理的数据<#if success>成功<#else>失败</#if>")
	public Object get(@RequestParam("id") String id, ModelMap modelMap) {
		WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(id);
		List<WQbdCalRewandpuns> wQbdCalRewandpunsList = wQbdCalRewandpunsService
				.getListByRefId(wQbdFalProblemreset.getId());
		wQbdFalProblemreset.setwQbdCalRewandpuns(wQbdCalRewandpunsList);
		if (null == wQbdFalProblemreset) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return getResultDataError("get.failure");
		}
//        JSON.toJSONString(wQbdFalProblemreset)
		modelMap.addAttribute("data", wQbdFalProblemreset);
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return getResultDataSuccess("get.success", wQbdFalProblemreset);
	}

	/**
	 * 功能描述: 根据主键ID删除数据的通用删除方法
	 *
	 * @param: id 参数名称必须是"id"
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@PostMapping(UrlConstants.MODULE_FUNCTION_DELETE)
	@ResponseBody
	@Action(description = "根据主键ID删除质量问题管理数据", exectype = "删除日志", detail = "删除数据信息<#if success>成功<#else>失败</#if>")
	public Object delete(@RequestParam("id") String id, HttpServletRequest request)throws Exception {
		String userId = ContextUtil.getCurrentUserId();
		String[] ids = id.split(",");
		if (StringUtil.isEmpty(id)) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return fail("delete.failure.message");
		}
		for (String key : ids) {
			WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(key);
			if (Objects.nonNull(wQbdFalProblemreset.getReportStatus())
					&& !"11".equals(wQbdFalProblemreset.getReportStatus())
					&& !"4".equals(wQbdFalProblemreset.getReportStatus())
					&& !"25".equals(wQbdFalProblemreset.getReportStatus())) {

				SysAuditThreadLocalHolder.putParamerter("success", false);
				return fail("删除失败，只允许删除待上报、无需上报、院内待审批的数据");
			}
			if (!FlowStatusEnum.getEnumByValue(wQbdFalProblemreset.getFlowStatus()).isDel()) {
				return fail("删除失败！不允许删除流程未结束数据！");
			}

			SysRole sysRole = (SysRole) request.getSession().getAttribute(SysRole.CURRENT_SYSROLE);
			if (!userId.equals(wQbdFalProblemreset.getfCreateby())) {
				if (!sysRole.getAlias().equals("bpm_zlzhzly")) {
					SysAuditThreadLocalHolder.putParamerter("success", false);
					return fail("删除失败！只能删除自己创建的数据！");
				}
			}
			if (wQbdFalProblemreset.getFlowStatus().equals(FlowStatusEnum.DONE.getValue()) && !sysRole
					.getAlias()
					.equals("bpm_zlzhzly")) {
				return fail("删除失败！审批完成的数据无法删除！");
			}
		}
		int result=0;
		//质量问题流程实例删除
		for (String key : ids) {
			WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(key);
			if(!wQbdFalProblemreset.getFlowStatus().equals(FlowStatusEnum.NOT_SUBMIT.getValue()) && StringUtil.isNotEmpty(wQbdFalProblemreset.getFlowStatus())){
				ProcessRun processRun = processRunService.getByBusinessKey(key);
				if(processRun!=null){
					processRunService.deleteByProcessRun(processRun);
				}
			}
		}
		//遗留问题流程实例删除
		for (String key : ids) {
			WQbdFalProblemPlan wQbdFalProblemPlan = wQbdFalProblemPlanService.getOneById(key);
			if(wQbdFalProblemPlan!=null){
				key=wQbdFalProblemPlan.getId();
				if(!wQbdFalProblemPlan.getFlowStatus().equals(FlowStatusEnum.NOT_SUBMIT.getValue()) && StringUtil.isNotEmpty(wQbdFalProblemPlan.getFlowStatus())){
					ProcessRun processRun = processRunService.getByBusinessKey(key);
					if(!(wQbdFalProblemPlan.getFlowStatus().equals(FlowStatusEnum.DONE.getValue()))){
						if(processRun!=null){
							processRunService.recoverByRunId(processRun.getRunId());
						}
					}
					if(processRun!=null){
						processRunService.deleteByProcessRun(processRun);
					}
				}
				//遗留问题数据删除
				result = wQbdFalProblemPlanService.delById(key);
				if(result <= 0){
					SysAuditThreadLocalHolder.putParamerter("success", false);
					return getResultDataError("delete.failure");
				}
			}
		}
		//质量问题数据删除
		result = wQbdFalProblemresetService.delByIdArray(id.split(","));
		if (result > 0) {
			SysAuditThreadLocalHolder.putParamerter("success", true);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
		}
		return result > 0 ? getResultDataSuccess("delete.success")
				: getResultDataError("delete.failure");
	}

	/**
	 * 功能描述: 跳转到导入页面
	 *
	 * @return: java.lang.String
	 * @auther: hw
	 * @date: 2019-12-25 19:21:40
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/import")
	@Action(description = "跳转到质量问题管理导入页面", exectype = "页面跳转日志")
	public String viewImport() {
		return "wQbdFalProblemreset/import";
	}

	/**
	 * 功能描述: 跳转到导出选择字段页面
	 *
	 * @return: java.lang.String
	 * @auther: hw
	 * @date: 2019-12-25 19:21:40
	 */
	@RequestMapping(UrlConstants.VIEW_DISPATCH_PREFIX + "/export")
	@Action(description = "跳转到质量问题导出选择字段页面", exectype = "页面跳转日志")
	public String export(HttpServletRequest request, ModelMap modelMap) throws Exception {
		JSONObject jsonObject = AuxiliaryUtil.resolverModel(WQbdFalProblemreset.class);
		modelMap.put("tableInfo", jsonObject.toString());
		return "expImp/add";
	}

	/**
	 * 功能描述: 导出质量问题管理数据信息
	 *
	 * @param: [request] http请求
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping("/exportData")
	@Action(description = "导出质量问题管理数据信息", detail = "导出质量问题管理数据信息<#if success>成功<#else></#if>")
	public void exportData(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		SysAuditThreadLocalHolder.putParamerter("success", false);
		String[] id = RequestUtil.getStringAryByStr(request, "id");
		QueryFilter queryFilter = new QueryFilter(request, false);
		JSONArray dataArray = ZhiLiangConst.exportAddConditions(queryFilter, id);
		// 处理状态搜索
//        if (queryFilter.containsKey("reportStatusOne")) {
//            String status = String.valueOf(queryFilter.get("reportStatusOne"));
//            queryFilter.put("reportStatusOne", ZhiLiangConst.wrapStatusCode(status));
//        }
		List<WQbdFalProblemreset> wQbdFalProblemresets = this.wQbdFalProblemresetService
				.queryAll(queryFilter);
		if (wQbdFalProblemresets.isEmpty()) {
			wQbdFalProblemresets.add(new WQbdFalProblemreset());
		}
		new AbstractExpUtil() {
			@Override
			public String customAnalysis(String fieldName, String fieldValue) {
				return null;
			}
		}.executeExport(request, response, wQbdFalProblemresets, dataArray,
				AbstractExpUtil.ExpStyle.MANY_SHEET);
		SysAuditThreadLocalHolder.putParamerter("success", true);
	}

	/**
	 * 导入资源文件
	 *
	 * @param request MultipartHttpServletRequest
	 * @param response HttpServletResponse
	 * @throws Exception Exception
	 */
	@RequestMapping("/importData")
	@ResponseBody
	public Object importData(MultipartHttpServletRequest request, HttpServletResponse response)
			throws Exception {
		SysAuditThreadLocalHolder.putParamerter("success", false);
		MultipartFile multipartFile = request.getFile("file");
		TableEntity excelEntity = new CustomExcelReader().readFile(multipartFile.getInputStream());
		List<WQbdXhdh> xhdhList = wQbdXhdhService.getAll();
		//型号研制阶段
		List<Dictionary> xhyzjdList = dictionaryService.getByNodeKey("xhyzjd");
		//型号类别
		List<Dictionary> xhlbList = dictionaryService.getByNodeKey("xhlb");
		//工作阶段
		List<Dictionary> gzjdList = dictionaryService.getByNodeKey("gzjd");
		//生产分类
		List<Dictionary> scflList = dictionaryService.getByNodeKey("scfl");
		//故障件阶段
		List<Dictionary> gzjjdList = dictionaryService.getByNodeKey("gzjjd");

		//产品级别
		List<Dictionary> cpjbList = dictionaryService.getByNodeKey("cpjb");

		//是否三类问题
		List<Dictionary> spslwtList = dictionaryService.getByNodeKey("spslwt");
		//（故障产品）硬件/软件
		List<Dictionary> yjrjList = dictionaryService.getByNodeKey("yjrj");
		//原因分类（一级）
		List<Dictionary> yyflsList = dictionaryService.getByNodeKey("yyfls");
		//责任单位性质
		List<Dictionary> zrswxzList = dictionaryService.getByNodeKey("zrswxz");
		//是否
		List<Dictionary> sfList = dictionaryService.getByNodeKey("sf");
		//归零方式
		List<Dictionary> glfsList = dictionaryService.getByNodeKey("glfs");
		//解决情况
		List<Dictionary> jjqkList = dictionaryService.getByNodeKey("jjqk");

		//问题处理方式
		List<Dictionary> wtclfsList = dictionaryService.getByNodeKey("wtclfs");
		//责任追究类别
		List<Dictionary> zrzjlbList = dictionaryService.getByNodeKey("zrzjlb");
		List<String> fieldNameList = Lists.newArrayList();
		fieldNameList.add("fModeldevelopphase");
		fieldNameList.add("fWorkphase1");
		fieldNameList.add("fProduceclass");
		fieldNameList.add("fBreakphase");
		fieldNameList.add("fProductlevel");
		fieldNameList.add("fIfthree");
		fieldNameList.add("fSofthard");
		fieldNameList.add("fCausationclass1");
		fieldNameList.add("fCausationclass2");
		fieldNameList.add("fDutydeptnature");
		fieldNameList.add("fResettype");
		fieldNameList.add("fSolveresult");
		fieldNameList.add("fMeasureclass");
		fieldNameList.add("fDutyinvestigationtyp");
		fieldNameList.add("fIffirstfly");
		fieldNameList.add("fIfshooting");
		fieldNameList.add("fIfbatch");
		fieldNameList.add("fIfreset");
		fieldNameList.add("fIfmating");
		fieldNameList.add("fConfirmdutyinvest");
		fieldNameList.add("fDutydept");
		List<Dictionary> orgDicList;
		int numberLevel = BaseUtil.getCurrentSystemNumberLevel();
		if (numberLevel == 2) {
			DictionaryService dictionaryService = AppUtil.getBean(DictionaryService.class);
			orgDicList = dictionaryService.getByNodeKey("sjdwzd");
		} else {
			ExtendSysOrgService extendSysOrgService = AppUtil.getBean(ExtendSysOrgService.class);
			orgDicList = extendSysOrgService.getSubordinateUnits();
		}

		Map<String, Object> map = new AbstractImpUtil() {
			@Override
			public ReturnType customValidation(String fieldName, String fieldValue) {
				ReturnType returnType = null;
				if ("fModelsymbol".equals(fieldName)) {
					// 判断型号是否存在，琳:如果没有这个型号名称或型号代号导入的时间判断不让导入
					returnType = new AbstractImpUtil.ReturnType();
					boolean sign = true;
					for (WQbdXhdh xhdh : xhdhList) {
						if (xhdh.getfModelcode().equals(fieldValue)) {
							returnType.setNewValue(xhdh.getfModelcode());
							sign = false;
							break;
						}
					}
					if (sign) {
						returnType.setMsg("非法的值!");
					}
				} else if ("fModelname".equals(fieldName)) {
					returnType = new AbstractImpUtil.ReturnType();
					boolean sign = true;
					for (WQbdXhdh xhdh : xhdhList) {
						if (xhdh.getfModelname().equals(fieldValue)) {
							returnType.setNewValue(xhdh.getfModelname());
							sign = false;
							break;
						}
					}
					if (sign) {
						returnType.setMsg("非法的值!");
					}

				} else if (fieldNameList.contains(fieldName)) {
					List<Dictionary> dictionaryList = Lists.newArrayList();
					switch (fieldName) {
						case "fModeldevelopphase":
							dictionaryList = xhyzjdList;
							break;
						case "fWorkphase1":
							dictionaryList = gzjdList;
							break;
						case "fProduceclass":
							dictionaryList = scflList;
							break;
						case "fBreakphase":
							dictionaryList = gzjjdList;
							break;
						case "fProductlevel":
							dictionaryList = cpjbList;
							break;
						case "fIfthree":
							dictionaryList = spslwtList;
							break;
						case "fSofthard":
							dictionaryList = yjrjList;
							break;
						case "fCausationclass1":
							dictionaryList = yyflsList;
							break;
						case "fCausationclass2":
							dictionaryList = yyflsList;
							break;
						case "fDutydeptnature":
							dictionaryList = zrswxzList;
							break;
						case "fResettype":
							dictionaryList = glfsList;
							break;
						case "fSolveresult":
							dictionaryList = jjqkList;
							break;
						case "fMeasureclass":
							dictionaryList = wtclfsList;
							break;
						case "fDutyinvestigationtyp":
							dictionaryList = zrzjlbList;
							break;
						case "fIffirstfly":
							dictionaryList = sfList;
							break;
						case "fIfshooting":
							dictionaryList = sfList;
							break;
						case "fIfbatch":
							dictionaryList = sfList;
							break;
						case "fIfreset":
							dictionaryList = sfList;
							break;
						case "fIfmating":
							dictionaryList = sfList;
							break;
						case "fConfirmdutyinvest":
							dictionaryList = sfList;
							break;
						case "fDutydept":
							dictionaryList = orgDicList;
							break;
					}
					returnType = new AbstractImpUtil.ReturnType();
					boolean sign = true;
					for (Dictionary dictionary : dictionaryList) {
						if (dictionary.getItemName().equals(fieldValue)) {
							returnType.setNewValue(dictionary.getItemName());
							sign = false;
							break;
						}
					}
					if (sign) {
						returnType.setMsg("非法的值!");
					}
				} else if ("fAllcount".equals(fieldName)) {
					returnType = new AbstractImpUtil.ReturnType();
					boolean sign = false;
					if (StringUtils.isNotBlank(fieldValue)) {
						returnType.setNewValue(fieldValue.replace(",", ""));
					}
				} else if ("fTotalnumber".equals(fieldName) || "fPunishmentnumber".equals(fieldName)) {
					returnType = new AbstractImpUtil.ReturnType();
					boolean sign = true;
					if (StringUtils.isNotBlank(fieldValue)) {
						try {
							Integer.parseInt(fieldValue.replace(",", ""));
							returnType.setNewValue(fieldValue.replace(",", ""));
							sign = false;
						} catch (Throwable t) {
						}
						if (sign) {
							returnType.setMsg("非法的值,只能填写数字!");
						}
					}
				}
				return returnType;
			}
		}.reverseModels(excelEntity, WQbdFalProblemreset.class);
		String msg = map.get("msg").toString();
		List<WQbdFalProblemreset> list = (List<WQbdFalProblemreset>) map.get("instList");
		if (StringUtil.isEmpty(msg)) {
			this.wQbdFalProblemresetService.addImportData(list);
			SysAuditThreadLocalHolder.putParamerter("success", true);
			return getResultDataSuccess("dataSource.importXml.success");
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return fail(msg);
		}
	}


	@Resource
	private SysFileService sysFileService;
	@Resource
	private ExtendSysFileService extendSysFileService;

	@RequestMapping("/createPDF")
	@Action(description = "生成质量问题PDF", detail = "生成涉质量问题PDF<#if success>成功<#else></#if>")
	@ResponseBody
	public void createPDF(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//新建下载目录
		//为保证目录不重复 生成时间戳
		String attachPath = ServiceUtil.getBasePath();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss");
		String sendName = simpleDateFormat.format(new Date());
		String fileName = "质量问题-" + sendName;
		String downloadPath =
				StringUtil.trimSufffix(attachPath, File.separator) + File.separator + fileName + ".zip";
		String folderPath =
				StringUtil.trimSufffix(attachPath, File.separator) + File.separator + fileName;
		String tempPic = folderPath + File.separator + fileName + ".jpg";
		String tempPdf = folderPath + File.separator + fileName + ".pdf";
		File dir = new File(folderPath);
		dir.mkdirs();
		String picStr = RequestUtil.getString(request, "picstr");
		Base64Util.decodeBase64ToFile(picStr, tempPic);

		//String id = RequestUtil.getString(request, "id");
		//String sanyuan = RequestUtil.getString(request, "sanyuan");

		PdfUtils.image2Pdf(tempPic, tempPdf);
		Files.delete(new File(tempPic).toPath());
		//执行文件压缩
		compress(folderPath, downloadPath);
		fileName = fileName + ".zip";
		String dowloadFile =
				StringUtil.trimSufffix(attachPath, File.separator) + File.separator + fileName;
		FileUtil.downLoadFile(request, response, dowloadFile, fileName);
		//删除上述新建的目录
		File folder = new File(folderPath);
		if (folder.exists() && folder.canWrite()) {
			FileUtil.deleteDir(folder);
		}
	}

	/**
	 * 功能描述: 跳转到新增页面
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(
			UrlConstants.VIEW_DISPATCH_PREFIX + UrlConstants.MODULE_FUNCTION_ADD_UPDATE + "Plan")
	@Action(description = "跳转到遗留问题计划新增页面", exectype = "页面跳转日志")
	public String viewAddPlan(HttpServletRequest request, ModelMap modelMap) {
		String flag = RequestUtil.getString(request, "flag");
		modelMap.put("flag", flag);
		String id = RequestUtil.getString(request, "id");
		modelMap.put("flag", flag);
		if (flag.equals("1")) {

			id = wQbdFalProblemPlanService.getByTrueId(id).getProblemId();
		}
		modelMap.put("id", id);
		List<SysUser> sysUsers = sysUserService
				.queryUserListByOrgId(sysOrgService
						.getSysOrgByOrgCode(wQbdFalProblemresetService.getOneById(id).getfDutydeptRoom())
						.getOrgId());
		modelMap.put("userList", JSON.toJSONString(sysUsers));

		WQbdFalProblemPlan wQbdFalProblemPlan = wQbdFalProblemPlanService.getOneById(id);
		String trueId = wQbdFalProblemPlan.getId();
		if (null == wQbdFalProblemPlan) {
			return "wQbdFalProblemreset/addPlan";
		}
			String runId = "";
			List<TaskOpinion> taskOpinionNewList = new ArrayList<TaskOpinion>();
			ProcessRun processRun = processRunService.getByBusinessKey(trueId);
			if (BeanUtils.isNotEmpty(processRun)) {
				runId = processRun.getRunId();
				List<TaskOpinion> taskOpinionList = taskOpinionService.getByRunId(runId);
				for (TaskOpinion taskOpinion : taskOpinionList) {
					if (taskOpinion.getEndTime() != null) {
						taskOpinionNewList.add(taskOpinion);
					}
				}
			}
		modelMap.put("taskOpinionNewList", taskOpinionNewList);
		modelMap.put("runId", runId);
		modelMap.put("processRun", processRun);
		modelMap.put("flowStatus", wQbdFalProblemPlan.getFlowStatus());
		modelMap.put("secret", wQbdFalProblemresetService.getOneById(id).getSecret());
		SysRole sysRole = (SysRole) request.getSession().getAttribute(SysRole.CURRENT_SYSROLE);
		if (wQbdFalProblemPlan.getUserId().equals(scriptImpl.getCurrentUserId()) && wQbdFalProblemPlan
				.getFlowStatus().equals(FlowStatusEnum.APPROVAL_ING.getValue())) {
			if (null != wQbdFalProblemPlan.getUserId()) {
				modelMap.put("isInclude", "true");
			}
			return "wQbdFalProblemreset/addPlan";
		}

		if (!wQbdFalProblemPlan.getUserId().equals(scriptImpl.getCurrentUserId()) && wQbdFalProblemPlan
				.getFlowStatus().equals(FlowStatusEnum.DONE.getValue()) && sysRole.getAlias()
				.equals("bpm_xhzgzly")) {
			if (null != wQbdFalProblemPlan.getMaterial()) {
				modelMap.put("isInclude", "true");
			}
			modelMap.put("rolAlias", sysRole.getAlias());
			return "wQbdFalProblemreset/addPlan";
		}
		if (!wQbdFalProblemPlan.getUserId().equals(scriptImpl.getCurrentUserId()) && !sysRole.getAlias()
				.equals("bpm_xhzgzly")) {
			if (null != wQbdFalProblemPlan.getMaterial()) {
				modelMap.put("isInclude", "true");
			}
			return "wQbdFalProblemreset/planDetail";
		}
		if (null != wQbdFalProblemPlan && wQbdFalProblemPlan.getFlowStatus()
				.equals(FlowStatusEnum.APPROVAL_ING2.getValue())) {
			modelMap.put("isInclude", "true");
			return "wQbdFalProblemreset/addPlan";
		}
		if (null != wQbdFalProblemPlan && wQbdFalProblemPlan.getFlowStatus()
				.equals(FlowStatusEnum.NOT_SUBMIT.getValue())) {
			modelMap.put("isInclude", "false");
			return "wQbdFalProblemreset/addPlan";
		}
		String isClose = RequestUtil.getString(request, "isClose");
		modelMap.put("id", id);
		modelMap.put("isClose", isClose);
		return "wQbdFalProblemreset/planDetail";
	}

	/**
	 * 功能描述:  数据保存通用方法
	 *
	 * @param: wQbdFalProblemreset 保存的对象
	 * @return: java.lang.Object
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping(UrlConstants.MODULE_FUNCTION_SAVE + "Plan")
	@ResponseBody
	@Action(description = "保存遗留问题计划数据", detail = "<#if isAdd>新增<#else>编辑</#if>质量问题管理数据<#if success>成功<#else>失败</#if>")
	public Object savePlan(@RequestBody WQbdFalProblemPlan wQbdFalProblemPlan) {
		String id = wQbdFalProblemPlan.getId();
		int result;
		if (StringUtil.isEmpty(id)) {
			SysAuditThreadLocalHolder.putParamerter("isAdd", true);
			//新增操作
			//新增数据前生成随机Id
			wQbdFalProblemPlan.setId(ProjectUUIDUtils.getUUIDFor32());
			wQbdFalProblemPlan.setFlowStatus(FlowStatusEnum.NOT_SUBMIT.getValue());
			result = wQbdFalProblemPlanService.add(wQbdFalProblemPlan);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			//修改操作
			result = wQbdFalProblemPlanService.update(wQbdFalProblemPlan);
		}
		if (result > 0) {
			SysAuditThreadLocalHolder.putParamerter("success", true);
		} else {
			SysAuditThreadLocalHolder.putParamerter("success", false);
		}
		Map<String, Object> idMap = Maps.newHashMap();
		idMap.put("id", wQbdFalProblemPlan.getId());
		return result > 0 ? getResultDataSuccess("save.success", idMap)
				: getResultDataError("save.failure");
	}

	@RequestMapping("/getPlan")
	@ResponseBody
	@Action(description = "获取遗留问题计划", exectype = "页面跳转日志")
	public Object getPlan(String id) {
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return
				getResultDataSuccess("get.success", wQbdFalProblemPlanService.getOneById(id));
	}

	/**
	 * 功能描述: 启动流程
	 */
	@PostMapping("/run")
	@ResponseBody
	@Action(description = "启动质量问题管理流程", detail = "启动流程<#if success>成功<#else></#if>")
	public Object run(HttpServletRequest request,
			@RequestBody WQbdFalProblemreset wQbdFalProblemreset) {
		SysUser sysUser = (SysUser) ContextUtil.getCurrentUser();
		//实体主键
		String id = wQbdFalProblemreset.getId();
		int isList = RequestUtil.getInt(request, "isList", 1);
		ProcessCmd processCmd = new ProcessCmd();
		//流程Key
		processCmd.setModelKey("glbghspzmssplc1");
		processCmd.setUserAccount(sysUser.getAccount());
		try {
			if (isList == 1) {
				wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(id);
			}
			processCmd.setBusinessKey(id);
			wQbdFalProblemreset.setFlowStatus(FlowStatusEnum.APPROVAL_ING.getValue());
			processRunService.startProcess(processCmd);
			wQbdFalProblemresetService.update(wQbdFalProblemreset);
			SysAuditThreadLocalHolder.putParamerter("success", true);
			return getResultDataSuccess("flow.start.success");
		} catch (Exception e) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return getResultDataError("flow.start.failure");
		}
	}

	/**
	 * 功能描述: 启动流程
	 */
	@PostMapping("/runPlan")
	@ResponseBody
	@Action(description = "启动w_qbd_fal_problem_plan流程", detail = "启动流程<#if success>成功<#else></#if>")
	public Object planRun(HttpServletRequest request,
			@RequestBody WQbdFalProblemPlan wQbdFalProblemPlan) {
		SysUser sysUser = (SysUser) ContextUtil.getCurrentUser();
		//实体主键
		String id = wQbdFalProblemPlan.getId();
		int isList = RequestUtil.getInt(request, "isList", 1);
		ProcessCmd processCmd = new ProcessCmd();
		//流程Key
		processCmd.setModelKey("ylwtrwsplc");
		processCmd.setUserAccount(sysUser.getAccount());
		try {
			if (isList == 1) {
				wQbdFalProblemPlan = wQbdFalProblemPlanService.getByTrueId(id);
			}
			processCmd.setBusinessKey(id);
			wQbdFalProblemPlan.setFlowStatus(FlowStatusEnum.APPROVAL_ING.getValue());
			processRunService.startProcess(processCmd);
			wQbdFalProblemPlanService.update(wQbdFalProblemPlan);
			SysAuditThreadLocalHolder.putParamerter("success", true);
			return getResultDataSuccess("flow.start.success");
		} catch (Exception e) {
			SysAuditThreadLocalHolder.putParamerter("success", false);
			return getResultDataError("flow.start.failure");
		}
	}


	@RequestMapping("/getCountByTime")
	@ResponseBody
	@Action(description = "获取当天质量问题数量", detail = "查询数据信息<#if success>成功<#else></#if>")
	public Object getCountByTime(HttpServletRequest request) throws IllegalAccessException {
		QueryFilter queryFilter = new QueryFilter(request, false);
		ZhiLiangConst.addQueryFilter(queryFilter);
		List<WQbdFalProblemreset> pageDatas = wQbdFalProblemresetService.queryList(queryFilter);
		SysAuditThreadLocalHolder.putParamerter("success", true);
		return success(pageDatas,pageDatas.size());

	}

	/**
	 * 功能描述: 跳转到首页
	 *
	 * @return: java.lang.String
	 * @auther: sun
	 * @date: 2020-05-06 15:57:36
	 */
	@RequestMapping("/view/history")
	@Action(description = "跳转到质量问题关联分析界面", exectype = "页面跳转日志")
	public String viewHistory(HttpServletRequest request, ModelMap modelMap) {
			modelMap.put("fProductname",RequestUtil.getString(request,"fProductname"));
		return "wQbdFalProblemreset/history";
	}


}
